package com.travel.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.travel.system.entity.TravelGuide;
import com.travel.system.mapper.TravelGuideMapper;
import com.travel.system.service.TravelGuideService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class TravelGuideServiceImpl extends ServiceImpl<TravelGuideMapper, TravelGuide> implements TravelGuideService {

    @Override
    public List<TravelGuide> getFive() {
        List<TravelGuide> list = this.list(new LambdaQueryWrapper<TravelGuide>().orderByDesc(TravelGuide::getId));
        List<TravelGuide> res = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(list)) {
            res = list.stream().limit(5).collect(Collectors.toList());
        }
        return res;
    }
}
